package com.ssy.lingxi.member.merchant.controller.feign;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.api.constant.AuthTypeEnum;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.request.AuthConfigVO;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.request.DeleteAuthConfigVO;
import com.ssy.lingxi.member.merchant.entity.MemberAuthTypeConfigDO;
import com.ssy.lingxi.member.merchant.service.feign.IMemberAuthTypeConfigFeignService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author lqa
 * @version 2.0.0
 * @menu 实名验证设置类
 * @date 2022/1/12
 */
@RestController
@RequestMapping("/member/config/auth")
public class MemberAuthTypeConfigFeignController {
    @Resource
    private IMemberAuthTypeConfigFeignService memberAuthTypeConfigFeignService;

    /**
     * 查询当前配置的实名验证类型
     *
     * @return 实名验证类型: 1-百度，
     */
    @RequestMapping(value = "/getAuthType", method = RequestMethod.POST)
    public Wrapper<Integer> getAuthType() {
        MemberAuthTypeConfigDO memberAuthTypeConfigDO = memberAuthTypeConfigFeignService.findEnableAuthConfig();
        if (memberAuthTypeConfigDO != null) {
            return Wrapper.success(memberAuthTypeConfigDO.getAuthType());
        } else {
            return Wrapper.success(AuthTypeEnum.BAI_DU.getCode());
        }
    }

    /**
     * 添加或修改实名验证公共参数
     *
     * @param authConfigVO 实名验证公共参数
     * @return 操作结果
     */
    @RequestMapping(value = "/saveOrUpdateAuthConfig", method = RequestMethod.POST)
    public Wrapper<Boolean> saveOrUpdateAuthConfig(@RequestBody @Valid AuthConfigVO authConfigVO) {
        return Wrapper.success(memberAuthTypeConfigFeignService.saveOrUpdateAuthConfig(authConfigVO));
    }

    /**
     * 删除实名验证公共参数
     *
     * @param deleteAuthConfigVO 请求参数
     * @return 操作结果
     */
    @RequestMapping(value = "/deleteAuthConfig", method = RequestMethod.POST)
    public Wrapper<Boolean> deleteAuthConfig(@RequestBody @Valid DeleteAuthConfigVO deleteAuthConfigVO) {
        return Wrapper.success(memberAuthTypeConfigFeignService.deleteAuthConfig(deleteAuthConfigVO));
    }
    /**
     * 清空实名验证内容
     *
     * @return 是否成功
     */
    @RequestMapping(value = "/member/config/auth/clearAuth", method = RequestMethod.POST)
    public Wrapper<Boolean> clearAuth() {
        return Wrapper.success(memberAuthTypeConfigFeignService.clearAuth());
    }
}
